package chabernac.android.wordbattle.paint.crosstile;

import android.graphics.Bitmap;
import chabernac.android.wordbattle.WordBattleView;
import chabernac.android.wordbattle.model.Letter;
import chabernac.android.wordbattle.model.Word;

public abstract class AbstractHalfCrossTileDrawable extends AbstractCrossTileDrawable 
{

	protected final Letter myLetterUpOrLeft;
	protected final Letter myLetterDownOrRight;
	
	public AbstractHalfCrossTileDrawable(
			Word aSelectedWord, 
			Letter aLetterUpOrLeft, 
			Letter aLetterDownOrRight)
	{
		super(aSelectedWord);
		myLetterUpOrLeft = aLetterUpOrLeft;
		myLetterDownOrRight = aLetterDownOrRight; 
	}
	
	@Override
	protected Bitmap getBitmap(WordBattleView aWordBattleView)
	{
		SvgResourceNameBuilder aBuilder = new SvgResourceNameBuilder();
		// Add selection string of down left	
		addSvgResourceNameSelectionString(aBuilder, myLetterUpOrLeft);
		// Add selection string of down right	
		addSvgResourceNameSelectionString(aBuilder, myLetterDownOrRight);
		// return the cross tile bitmap
		return CrossTileBitmapFactory.getInstance().getCrossTileBitmap(aBuilder.getResourceName(), aWordBattleView);
	}
	
	protected void addSvgResourceNameSelectionString(SvgResourceNameBuilder aBuilder, Letter aLetter)
	{
		if (addSvgResourceNameSelectionStringSingleLetter(aBuilder, aLetter))
		{
			Letter aNextLetter = mySelectedWord.getNextSelectedLetter(aLetter);
			addSvgResourceNameSelectionStringSingleLetter(aBuilder, aNextLetter);
			Letter aPreviousLetter = mySelectedWord.getPreviousSelectedLetter(aLetter);
			addSvgResourceNameSelectionStringSingleLetter(aBuilder, aPreviousLetter);
			aBuilder.appendSelectionBreak();
		}
	}
	
	protected abstract boolean addSvgResourceNameSelectionStringSingleLetter(SvgResourceNameBuilder aBuilder, Letter aLetter);
}
